// 本项目实现简单的编程式导航

import router from '../../config/router.config';
// 此处设置项目中router文件地址
import { history } from 'umi';

const basic_path = router.filter((e) => e.path === '/');
let path = [];
if (basic_path.length) {
  path = basic_path[0].routes[0].routes;
}

function arouter(args) {
  console.log(args,path)
  let real_path = '';
  if (args.hasOwnProperty('path')) {
    real_path = args.path;
    delete args.path;
  }
  if (args.hasOwnProperty('name')) {
    console.log(args.name)
    const name_router = path.filter((e) => e.path_name === args.name);
    delete args.name;
    if (name_router.length) {
      real_path = name_router[0].path;
    } else {
      console.log('无法找到当前name');
    }
    args.pathname = real_path
  }
  console.log('args',args)
  history.push( args);

}

export default arouter;
